package com.mb.app.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import com.mb.app.domain.TbCouponCfg;
import com.mb.app.dao.TbCouponCfgMapper;

import com.mb.app.service.ITbCouponCfgService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 优惠劵配置  服务实现类
 * </p>
 *
 * @author liliping
 * @since 2019-05-20
 */
@Service
@Slf4j
public class TbCouponCfgServiceImpl extends ServiceImpl<TbCouponCfgMapper, TbCouponCfg> implements ITbCouponCfgService {

    @Override
    public List<TbCouponCfg> queryList(Map<String, Object> map) {
        List<TbCouponCfg> list = this.baseMapper.list(map);
        return list;
    }

    @Override
    public int count(Map<String, Object> map) {
        return this.baseMapper.count(map);
    }

    @Override
    public int save(TbCouponCfg TbCouponCfg) {
        TbCouponCfg.setCreateTime(new Date());
        return this.baseMapper.insert(TbCouponCfg);
    }

    @Override
    public int update(TbCouponCfg TbCouponCfg) {
        try {
            TbCouponCfg TbCouponCfg1 = new TbCouponCfg();
            TbCouponCfg1.setCouponCfgId(TbCouponCfg.getCouponCfgId());
            TbCouponCfg1.setDataStatus(1);
            TbCouponCfg TbCouponCfgDO = this.baseMapper.selectOne(TbCouponCfg1);
            if(TbCouponCfgDO != null){
                this.baseMapper.updateById(TbCouponCfg);
            }
        } catch (Exception e) {
            log.error("update Exception",e);
        }
        return 0;
    }


    @Override
    public int remove(Long couponCfgId) {
        TbCouponCfg TbCouponCfg = new TbCouponCfg();
        TbCouponCfg.setCouponCfgId(couponCfgId);
        /*TbCouponCfg.setDeleteTime(new Date());*/
        TbCouponCfg.setDataStatus(0);
        /*TbCouponCfg.setDeleteUserId(delUserId);*/
        return this.baseMapper.updateById(TbCouponCfg);
    }

    @Override
    public TbCouponCfg getDtl(Long couponCfgId) {
        TbCouponCfg TbCouponCfg = this.baseMapper.selectById(couponCfgId);
        return TbCouponCfg;
    }

    @Override
    public boolean couponCfgNameExit(Map<String, Object> params) {
        boolean exit;
        exit = this.baseMapper.selectByCouponCfgInfo(params).size() > 0;
        return exit;
    }

    @Override
    public List<TbCouponCfg> queryListByType(Map<String, Object> map) {
        return null;
    }

    @Override
    public int countByType(Map<String, Object> map) {
        return 0;
    }
}
